package com.example.fridaykt.service.impl

import cn.dev33.satoken.stp.StpInterface
import com.example.fridaykt.model.SysRole
import com.example.fridaykt.model.roleName
import com.example.fridaykt.model.sysUsers
import com.example.fridaykt.model.userId
import com.example.fridaykt.repository.SysRoleRepository
import org.babyfish.jimmer.sql.kt.ast.expression.eq
import org.springframework.cache.annotation.Cacheable
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional

@Component
class StpInterfaceImpl(
    private val sysRoleRepository: SysRoleRepository,
) : StpInterface {
    override fun getPermissionList(loginId: Any, loginType: String): List<String> {
        val list: List<String> = ArrayList()
        return list
    }

    @Cacheable("sys_satoken")
    @Transactional
    override fun getRoleList(loginId: Any, loginType: String): List<String> {
        val id = loginId as Long
        val sysRoles = sysRoleRepository.sql.createQuery(SysRole::class) {
            where(table.sysUsers {
                userId eq id
            })
            select(
                table.roleName
            )
        }.execute()
        return sysRoles
    }
}